﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for KeyWords
/// </summary>
public class KeyWords
{
    private static sqlKeyWordsProvider master = new sqlKeyWordsProvider();
	public KeyWords()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static int getKeyIdByName(string KeyName)
    {
        return master.KeyIdByName(KeyName);
    }
    public static List<KeyItems>KeyWordsget()
    {
        return master.KeyWordsget();
    }
    public static int Insert(string KeyName)
    {
        return master.Insert(KeyName);
    }

    public static int Delete(int KeyId)
    {
        return master.Delete(KeyId);
    }
    public static int Update(int KeyId, string KeyName)
    {
        return master.Update(KeyId, KeyName);
    }
}

public class sqlKeyWordsProvider
{
    public int Delete(int KeyId)
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(KeyId);
        return Dal.ExecuteDBspNonQuery("usp_KeyWordsDelete", Dal.arParams);
    }

    public int Update(int KeyId, string KeyName)
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(KeyName);
        Dal.arParams.Add(KeyId);
        return (int)Dal.ExecuteDBspOneValue("usp_KeyWordUpdate", Dal.arParams);
    }

    public List<KeyItems> KeyWordsget()
    {
        List<KeyItems> list = new List<KeyItems>();

        DataTable DT = Dal.ExecuteDBsp("usp_KeyWordsget");
        if (DT != null)
            if (DT.Rows.Count > 0)
            {
                KeyItems f;
                foreach (DataRow DR in DT.Rows)
                {
                    f = new KeyItems();
                    f.KeyName = DR["KeyName"].ToString();
                    f.KeyId = Convert.ToInt32(DR["KeyId"]);
                    f.KeyState = Convert.ToInt32(DR["KeyState"]);
                    list.Add(f);
                }
            }
        return list;
    }

    public int Insert(string KeyName)
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(KeyName);
        return (int)Dal.ExecuteDBspOneValue("usp_KeyWordInsert", Dal.arParams);
    }

    public int KeyIdByName(string KeyName)
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(KeyName);
        return (int)Dal.ExecuteDBspOneValue("usp_getKeyIdByName",Dal.arParams);
    }
}
[Serializable]
public class KeyItems
{
    public String _KeyName;
    public int _KeyState;
    public int _KeyId;

    public KeyItems()
    { }

    public string KeyName
    {
        get
        {
            return _KeyName;
        }
        set
        {
            _KeyName = value;
        }
    }
    public int KeyState
    {
        get
        {
            return _KeyState;
        }
        set
        {
            _KeyState = value;
        }
    }
    public int KeyId
    {
        get
        {
            return _KeyId;
        }
        set
        {
            _KeyId = value;
        }
    }
}

public class HandFinderKeys
{
    private string keyword ;

    public HandFinderKeys(string lookingForCitys)
    {
        keyword = lookingForCitys;
}
    public bool Match(KeyItems item)
    {
        return item.KeyName.Contains(keyword);
    }
}

public class HandFinderKeysbyIds
{
    private int x;
    public HandFinderKeysbyIds(int x)
    {
        this.x = x;
    }
    public bool Match(KeyItems item)
    {
        return (item.KeyId == x);
    }
}
